<?php

/**
 * Google Friend Connect(GFC) Integration
 * 
 * @package ElggGFC
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
 * @author Arunoda Susiripala
 * @copyright Arunoda Susiripala 2009
 * @link http://elgggfc.googlecode.com
 */	

if(!isloggedin()) {
?>
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load('friendconnect', '0.8');
</script>

<script type="text/javascript">    

	function setGFC(){
		
		var target=document.getElementById("gfc_login_icon");
		if(!target) return;
		
		google.friendconnect.container.setParentUrl('mod/gfc/');
		  google.friendconnect.container.loadOpenSocialApi({
		    site: '<?php echo $CONFIG->GFC_SITE_ID;?>',
		    onload: function(securityToken) {
		    	 if (!window.timesloaded) {
		    	      window.timesloaded = 1;
		    	    } else {
		    	      window.timesloaded++;
		    	    }
		    	    if (window.timesloaded > 1) {
		    	      window.top.location.reload();
		    	    }
		        }
		  });

		  google.friendconnect.renderSignInButton({ 'id': 'gfc_login_icon', 'text' : 'Click here to join ', 'style': 'standard' });
				
	}

  $(document).ready(function() {
      setGFC();
  });
</script>

<?php }?>

<?php 
//load api for the Settings page (user settings)...
$page=preg_replace('/\/.*/',"",preg_replace("/.*pg\//",'',getenv("REQUEST_URI")));
if($page=='settings'){?>
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load('friendconnect', '0.8');
</script>
<script type="text/javascript">    
google.friendconnect.container.loadOpenSocialApi({
  site: '<?php echo $CONFIG->GFC_SITE_ID;?>'
});
</script>
<?php }?>